package com.knowif.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.knowif.dao.LabelMapper;
import com.knowif.pojo.Label;
import com.knowif.pojo.LabelExample;

@Service
public class Label_service {
	
	@Autowired
	private LabelMapper labelMapper;
	
	public List<Label> selectByUserIds(List<Integer> userIds) {
		if(userIds ==null || userIds.isEmpty()){
			return new ArrayList<Label>();	
		}
		LabelExample labelExample = new LabelExample();
		labelExample.createCriteria().andUserIdIn(userIds);
		List<Label> labels = labelMapper.selectByExample(labelExample);
		return labels;
	}

	
	public List<Label> selectByUserId(Integer userId) {
		if(userId ==null){
			return new ArrayList<Label>();	
		}
		LabelExample labelExample = new LabelExample();
		labelExample.createCriteria().andUserIdEqualTo(userId);
		List<Label> labels = labelMapper.selectByExample(labelExample);
		return labels;
	}
	
	
	public int deleteByUserId(Integer userId) {
		if(userId ==null){
			return 0;	
		}
		LabelExample labelExample = new LabelExample();
		labelExample.createCriteria().andUserIdEqualTo(userId);
		return labelMapper.deleteByExample(labelExample);
	}
	
	
	public int deleteByUserIds(List<Integer> userIds) {
		if(userIds ==null || userIds.isEmpty()){
			return 0;	
		}
		LabelExample labelExample = new LabelExample();
		labelExample.createCriteria().andUserIdIn(userIds);
		return labelMapper.deleteByExample(labelExample);
	}
	
	
	public int save(Label label){
		if(label == null){
			return 0;
		}
		return labelMapper.insert(label);
	}
}
